package me.yuzho.study.concurrency;

import static net.mindview.util.Print.*;

/** 被互斥所阻塞: 同一个互斥可以被同一个任务多次获取
 * @author yzhou-citrix
 *
 */
public class Multilock {

    public synchronized void f1(int count) {
        if(count-- > 0) {
            print("f1() calling f2() with count " + count);
            f2(count);
        }
    }
    
    public synchronized void f2(int count) {
        if(count-- > 0) {
            print("f2() calling f1() with count " + count);
            f1(count);
        }
    }
    
    public static void main(String[] args) {
        final Multilock multiLock = new Multilock();
        
        new Thread() {
            public void run() {
                multiLock.f1(10);
            }
        }.start();
    }
}
